﻿using System;
using System.Collections.Generic;
using EzDesk.DesktopClient.Event;
using EzDesk.DesktopClient.FunctionWindowModule;
using EzDesk.DesktopClient.FunctionWindowModule.ViewModel;
using Microsoft.Practices.Unity;
using Moq;
using NUnit.Framework;
using ContainerControlledLifetimeManager = Microsoft.Practices.Unity.ContainerControlledLifetimeManager;

namespace EzDesk.DesktopClient.UnitTest.FunctionWindowModule_Fixture
{
    [TestFixture]
    public class FunctionWindowModuleControllerFixture
    {
        [Test]
        public void on_FunctionNavigateEvent_happen_with_url_is_action_url()
        {
            var mockUrl = "http://comsadf?target=action";
            var mockUrlWithToken = "http://comsadf?target=action&ez_user_token=sldfjals;djfl";
            var m_ActionViewModel = new Mock<IActionViewModel>();
            var m_UserManagement = new Mock<IUserManagement>();
            m_UserManagement.Setup(um => um.GetUrlWithUserToken(mockUrl)).Returns(mockUrlWithToken);
            UnityContainer unityContainer = new UnityContainer();
            unityContainer.RegisterType<IFunctionPageViewModel, FunctionPageViewModel>();

            var functionWindowModuleController = new FunctionWindowModuleController(m_ActionViewModel.Object, new List<IFunctionPageViewModel>(), m_UserManagement.Object, unityContainer);
            functionWindowModuleController.OnFunctionNavigate(new FunctionNavigateArgs() { Url = mockUrl });

            m_ActionViewModel.Verify(av=>av.DoAction(mockUrlWithToken));
        }
    }
}
